function save() {
    var list =[];
    var reportId = $("#reportId").val();
    $("#Form input,#Form textarea").each(function () {
        var write = {};
        var inputName = $(this).attr("name");
        var value = $(this).val();

        var writeId = document.getElementById(inputName).getAttribute("writeId");
      if (writeId !=undefined){
        write.writeId = writeId;
      }
        write.s1 = value;
        write.inputName = inputName;
        write.reportId = reportId;
        list.push(write);

    })
    $.ajax({
        type: "post",
        data: {"list":JSON.stringify(list)},
        url: "/write/setWrite",
        dataType: "json",
        success: function (data) {
            if (data.code == 1) {
                layer.alert(data.msg,function(){
                    layer.closeAll();
                  //  load(obj);
                });
            } else {
                layer.alert(data.msg);
            }
        },
        error: function () {
            layer.alert("操作请求错误，请您稍后再试",function(){
                layer.closeAll();
                //load(obj);
            });
        }
    });

}

$(function () {
    $(".year").html($("#year").val());
    $(".lastyear").html(Number( $("#year").val()) -1);
    $(".fifthyear").html(Number( $("#year").val()) +5);
    $.ajax({
        type: "post",
        data: {"reportId":$("#reportId").val()},
        url: "/write/getWrites",
        dataType: "json",
        success: function (data) {
            var columNum =  $("#body tr:first td").length-2;
            var row = data.length/columNum;
            initTable(row);
            //页面数据重显
            var industryName = $("#industryName").val();
            $(".industryLabel").each(function () {
                $(this).text(industryName);
            })

            for (var i = 0 ; i <data.length;i++){
                $("#"+data[i].inputName).val(data[i].s1);
                if (data[i].writeId !=null){
                    document.getElementById(data[i].inputName).setAttribute("writeId",data[i].writeId);
                }
            }
        },
        error: function () {
            layer.alert("操作请求错误，请您稍后再试",function(){
                layer.closeAll();
            });
        }
    });

    //添加一个弹窗
    var sHtml = "<i class='layui-icon' data-title='销售数据' onclick='openLayer()' style='font-size:20px;color:cornflowerblue; '>&#xe630;</i>";
    $(".title").append(sHtml);
})

function openLayer() {
    layer.open({
        type: 2 //此处以iframe举例
        ,title: '产品打开'
        ,area: ['1300px', '600px']
        ,shade: 0
        ,maxmin: true
        ,offset:'auto'
        ,content:'/write/saledata?industryId='+$("#industryId").val()+'&year='+$("#year").val()

    });

}